﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAccessLayer
{
    public class SupplierRepository
    {
        StationeryInventoryEntities1 ent;

        public SupplierRepository()
        {
            ent = new StationeryInventoryEntities1();
        }

        #region Select Method

        public List<Supplier> GetSupplierByItemCode(string itemCode)
        {
            List<Supplier> list = new List<Supplier>();

            //var supDetail = ent.SupplierDetails.Where(x => x.Stationery.ItemCode == itemCode);

            var sup = from sd in ent.SupplierDetails
                      where sd.ItemCode == itemCode
                      join s in ent.Suppliers on sd.SupplierID equals s.SupplierID
                      select s;

            //var sup = ent.Suppliers.Where(x => x.SupplierDetails.ItemCode == supDetail);

            if (sup != null)
            {
                list = sup.ToList();
            }
            //list = supDetail.ToList();
            return list;
        }

        public List<Supplier> GetAllSupplier()
        {
            List<Supplier> list = new List<Supplier>();

            var sup = ent.Suppliers.OrderBy(x => x.SupplierName);

            if (sup != null)
            {
                list = sup.ToList();
            }
            return list;
        }
        #endregion
    }
}
